<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/4/7
 * Time: 16:45
 */

namespace common\logics\depositrecord;

use common\widgets\Tool;
use Yii;
use yii\base\BaseObject;

class DepositRecordLogic extends BaseObject implements IDepositRecord
{
    /** @var \common\sources\read\businessdepositrecord\BusinessDepositRecordAccess $RBusinessDepositRecordAccess ****/
    private $RBusinessDepositRecordAccess;

    public function init()
    {
        $this->RBusinessDepositRecordAccess = Yii::$container->get("RBusinessDepositRecordAccess");
        parent::init(); // TODO: Change the autogenerated stub
    }

    public function getList($data)
     {
         if(empty($data['bus_id']))
         {
             return Tool::returnJson([],401,"商家用户id不能为空");
         }
         if(empty($data['safetyCode']))
         {
             return Tool::returnJson([],402,"安全码不能为空");
         }
         if($data['safetyCode'] != md5($data['bus_id']))
         {
             return Tool::returnJson([],403,"安全码不正确");
         }
         $count = $this->RBusinessDepositRecordAccess->getCount($data);
         $list = [];
         if($count >0)
         {
             $list = $this->RBusinessDepositRecordAccess->getList($data);
             foreach ($list as &$item)
             {
                 $item['task_order_num'] = empty($item['task_order_num']) ? 0:$item['task_order_num'];
                 $item['create_time'] = isset($item['create_time']) ? date('Y-m-d H:i:s',$item['create_time']) : '';
                 $item['task_id'] = empty($item['task_id']) ? $item['remark'] : (!empty($item['task_order_num'])?$item['task_order_num'] : $item['task_id']);
             }
         }
         return Tool::returnJson([
             "list" => $list,
             "page_num" => $data['page_num'],
             "count" => $count,
             "limit" => $data['limit'],
         ],200,"成功");
     }

     public function getRechargeList($data)
     {
         if(empty($data['bus_id']))
         {
             return Tool::returnJson([],401,"商家用户id不能为空");
         }
         if(empty($data['safetyCode']))
         {
             return Tool::returnJson([],402,"安全码不能为空");
         }
         if($data['safetyCode'] != md5($data['bus_id']))
         {
             return Tool::returnJson([],403,"安全码不正确");
         }
         $count = $this->RBusinessDepositRecordAccess->getRechargeCount($data);
         $list = [];
         if($count >0)
         {
             $list = $this->RBusinessDepositRecordAccess->getRechargeList($data);
             foreach ($list as &$item)
             {
                 $item['create_time'] = isset($item['create_time']) ? date('Y-m-d H:i:s',$item['create_time']) : '';
             }
         }
         return Tool::returnJson([
             "list" => $list,
             "page_num" => $data['page_num'],
             "count" => $count,
             "limit" => $data['limit'],
         ],200,"成功");
     }

     public function getRechargeTestList($data)
     {
         if(empty($data['bus_id']))
         {
             return Tool::returnJson([],401,"商家用户id不能为空");
         }
         if(empty($data['safetyCode']))
         {
             return Tool::returnJson([],402,"安全码不能为空");
         }
         if($data['safetyCode'] != md5($data['bus_id']))
         {
             return Tool::returnJson([],403,"安全码不正确");
         }
         $count = $this->RBusinessDepositRecordAccess->getRechargeCount($data);
         $list = [];
         if($count >0)
         {
             $list = $this->RBusinessDepositRecordAccess->getRechargeList($data);
             foreach ($list as &$item)
             {
                 $item['create_time'] = isset($item['create_time']) ? date('Y-m-d H:i:s',$item['create_time']) : '';
                 $item['income'] = isset($item['amount']) ? $item['amount'] : '';
             }
         }
         return Tool::returnJson([
             "list" => $list,
             "page_num" => $data['page_num'],
             "count" => $count,
             "limit" => $data['limit'],
         ],200,"成功");
     }

}